﻿using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Wy.JiZhangSoft.Dictionaries;
using Wy.JiZhangSoft.ZhangDans;

namespace Wy.JiZhangSoft.EntityFrameworkCore
{
    public static class JiZhangSoftDbContextModelCreatingExtensions
    {
        public static void ConfigureJiZhangSoft(this ModelBuilder builder)
        {
            Check.NotNull(builder, nameof(builder));

            /* Configure your own tables/entities inside here */

            //builder.Entity<YourEntity>(b =>
            //{
            //    b.ToTable(JiZhangSoftConsts.DbTablePrefix + "YourEntities", JiZhangSoftConsts.DbSchema);
            //    b.ConfigureByConvention(); //auto configure for the base class props
            //    //...
            //});

            builder.Entity<ZhangDan>(b =>
            {
                b.ToTable(JiZhangSoftConsts.MyDbTablePrefix + nameof(ZhangDan)+"s", JiZhangSoftConsts.DbSchema);
                b.ConfigureByConvention(); //auto configure for the base class props
                b.Property(x=>x.Price).IsRequired().HasPrecision(16, 4).IsRequired();
                b.Property(x => x.OriginPrice).HasPrecision(16, 4).IsRequired();
                b.Property(x => x.Name).IsRequired().HasMaxLength(50);
                b.Property(x => x.Classified).HasMaxLength(20);
            });

            builder.Entity<Dictionary>(b =>
            {
                b.ToTable(JiZhangSoftConsts.MyDbTablePrefix + "Dictionaries", JiZhangSoftConsts.DbSchema);
                b.ConfigureByConvention(); //auto configure for the base class props
                b.Property(x => x.Code).IsRequired().HasMaxLength(30);
                b.Property(x => x.Name).IsRequired().HasMaxLength(50);
                b.Property(x => x.Value).IsRequired().HasMaxLength(300);
            });

            builder.Entity<Files.File>(b =>
            {
                b.ToTable(JiZhangSoftConsts.MyDbTablePrefix + nameof(Files.File) + "s", JiZhangSoftConsts.DbSchema);
                b.ConfigureByConvention(); //auto configure for the base class props
                b.Property(x => x.Name).IsRequired().HasMaxLength(200);
                b.Property(x => x.Identification).IsRequired().HasMaxLength(300);
            });

            builder.Entity<LeiJiZhiChuStatistics>(b =>
            {
                b.ToTable(JiZhangSoftConsts.MyDbTablePrefix +nameof(LeiJiZhiChuStatistics), JiZhangSoftConsts.DbSchema);
                b.ConfigureByConvention(); //auto configure for the base class props
                b.Property(x => x.Price).IsRequired().HasPrecision(16, 4).IsRequired();
                b.Property(x => x.JinRiXiaoFei).IsRequired().HasPrecision(16, 4).IsRequired();
                b.Property(x => x.Day).IsRequired().HasMaxLength(20);
            });
            builder.Entity<MonthLatelyZhiChuStatistic>(b =>
            {
                b.ToTable(JiZhangSoftConsts.MyDbTablePrefix + "MonthLatelyZhiChuStatistics", JiZhangSoftConsts.DbSchema);
                b.ConfigureByConvention(); //auto configure for the base class props
                b.Property(x => x.Price).IsRequired().HasPrecision(16, 4).IsRequired();
            });
            builder.Entity<YearLatelyZhiChuStatistic>(b =>
            {
                b.ToTable(JiZhangSoftConsts.MyDbTablePrefix + "YearLatelyZhiChuStatistic", JiZhangSoftConsts.DbSchema);
                b.ConfigureByConvention(); //auto configure for the base class props
                b.Property(x => x.Price).IsRequired().HasPrecision(16, 4).IsRequired();
            });

            builder.Entity<Notes.Note>(b =>
            {
                b.ToTable(JiZhangSoftConsts.MyDbTablePrefix + "Notes", JiZhangSoftConsts.DbSchema);
                b.ConfigureByConvention(); //auto configure for the base class props
                b.Property(x => x.Show).HasMaxLength(70);
            });

            builder.Entity<Holidays.Holiday>(b =>
            {
                b.ToTable(JiZhangSoftConsts.MyDbTablePrefix + "Holidays", JiZhangSoftConsts.DbSchema);
                b.ConfigureByConvention(); //auto configure for the base class props
                b.Property(x => x.Date).HasMaxLength(20);
            });
        }
    }
}